<?php
/*
if(!isset($_SESSION['admin'])){
	global $CFG;
	$pageURL = (isset($_SERVER['HTTPS'] ) and $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
	$pageURL .= $_SERVER['SERVER_PORT'] != '80' ? $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"] : $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
	$_SESSION['back_url']=$pageURL;
	header("Location: ".$CFG->config['base_url'].'admin/index');
}*/
class adminMenu_index extends controller{
	public $adminMenu;
	public function __construct(){
		$this->adminMenu=$this->model()->getAdminMenu();
		return $this;
	}

	public function generateAdminMenu($adminMenus=array()){
		if(!empty($adminMenus)) $this->adminMenu=$adminMenus;
		global $CFG;
		$base_url=$CFG->config['base_url'];
		if(empty($this->adminMenu)) return false;
		
		$out="<ul role='navigation' id='adminmenu'>\n";
		foreach($this->adminMenu as $adminMenu){
			$class=$adminMenu->class;
			$id=trim($adminMenu->name)?"id='{$adminMenu->name}'":'';
			$href=trim($adminMenu->href)?"href='$base_url{$adminMenu->href}'":'';
			$name=trim($adminMenu->name)?$adminMenu->name:'';
			if(isset($adminMenu->subMenu))$class.=' wp-has-submenu wp-not-current-submenu ';
			if(trim($adminMenu->icon))$class.=$adminMenu->icon;
			$out.="<li $id class='{$class}'>\n";
			if(trim($name))
				$out.="<a $id class='{$adminMenu->class}' $href >
				<div class='wp-menu-arrow'><div></div></div>
				<div class='wp-menu-image'><br></div>
				<div class='wp-menu-name'>$name</div>
				</a>\n";
			if(isset($adminMenu->subMenu)){
				$out.="<ul class='wp-submenu wp-submenu-wrap'>\n";
						foreach ($adminMenu->subMenu as $subItem){
							$out.="<li id='{$subItem->name}' class='{$subItem->class}'>\n";
							$out.="<a id='{$subItem->name}' class='{$subItem->class}' href='$base_url{$subItem->href}'>{$subItem->name}</a>\n";
						}
						$out.="</ul>\n";
				}
				$out.="</li>\n";
		}
		return $out."</ul>\n";
	
	}
	
}